package com.spring.demo1.aliasfor;

import org.springframework.core.annotation.AnnotatedElementUtils;

/**
 * @author vhans
 */
@B(value = "Vhans", aValue = "通过B给A的value参数设置值")
@A1(v1 = "设置v1")
@B2(name = "设置BName")
public class Test {

    @A1(v2 = "设置v2")
    private String name;

    @org.junit.Test
    public void test() {
        // AnnotatedElementUtils是spring提供的一个查找注解的工具类
        System.out.println(AnnotatedElementUtils.getMergedAnnotation(Test.class, B.class));
        System.out.println(AnnotatedElementUtils.getMergedAnnotation(Test.class, A.class));
    }

    @org.junit.Test
    public void test1() throws NoSuchFieldException {
        System.out.println(AnnotatedElementUtils.getMergedAnnotation(Test.class, A1.class));
        System.out.println(AnnotatedElementUtils.getMergedAnnotation(Test.class.getDeclaredField("name"), A1.class));
    }

    @org.junit.Test
    public void test2() throws NoSuchFieldException {
        System.out.println(AnnotatedElementUtils.getMergedAnnotation(Test.class, B2.class));
        System.out.println(AnnotatedElementUtils.getMergedAnnotation(Test.class, A2.class));
    }
}
